package com.solvePlat.service.Impl;

import com.solvePlat.dao.UserFollowMapper;
import com.solvePlat.entity.UserFollow;
import com.solvePlat.entity.UserFollowExample;
import com.solvePlat.shiro.JWTToken;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

@Service
public class UserFollowServiceImpl {
    @Resource
    private UserFollowMapper userFollowMapper;

    public void followWorkInfo(UserFollow userFollow){
        JWTToken jwtToken = (JWTToken) SecurityUtils.getSubject().getPrincipal();
        userFollow.setUuid(UUID.randomUUID().toString());
        userFollow.setCreator(jwtToken.getUserId());
        userFollow.setType("1");//发布的任务信息
        userFollowMapper.insert(userFollow);
    }

    public void cancleFollowWorkInfo(UserFollow userFollow){//删除
        JWTToken jwtToken = (JWTToken) SecurityUtils.getSubject().getPrincipal();
        UserFollowExample userFollowExample = new UserFollowExample();
        userFollowExample.createCriteria()
                .andFollowresourcesidEqualTo(userFollow.getFollowresourcesid())
                .andCreatorEqualTo(jwtToken.getUserId());

        userFollowMapper.deleteByExample(userFollowExample);
    }
}
